from common.read_yaml import read_data_yaml, judge_code, change_channelCode, read_shebei_yaml
from utils.requestuntil import RequestUtil
import easygui as eg
from utils.readmysql import RdTestcase
from utils.logutil import logger

# 读取到的yaml文件信息
data_yaml = read_data_yaml()


# 出厂设置的默认值 【这个是为了避免每次都需要恢复出厂设置搞的】
LIST_YINGPING_DATA = []  # 音频数据
LIST_YIDONG_DATA = []    # 移动侦测
LIST_OSD_DATA = []       # osd
LIST_QUYURUQIN_DATA = []  # 区域入侵
LIST_GAOJING_DATA = []  # 告警
LIST_YESHI_DATA = []  # 夜视
LIST_YIDONG_BUCHUAN = []  # 针对移动部分时间段开关不传用
LIST_WANGLUO_DATA = []  # 网络

# ——————————————————音频相关------------------------------
# 音频__默认
def get_yinping():

    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getAudioConfig"

    res = RequestUtil.all_send_request('GET', url, params=data_yaml)

    code = res.json()['code']

    data = res.json()['data']

    LIST_YINGPING_DATA.append(res.json()['data'])

    judge_code(code=code)
    assert data['audioOutStatus'] == 2, logger.error("【扩音】默认：关")

    assert data['audioInStatus'] == 2, logger.error("默认【拾音】: 关")

    if data['audioOut'] <= 100 and data['audioOut'] >= 50:
        assert 1, logger.error("【扩音】声音量合规定为：[50,100]----->"+data['audioOut'])
    else:
        assert 0, logger.error("【扩音】声音大小不符合规定")

    if data['audioIn'] <= 100 and data['audioIn'] >= 50:
        assert 1, logger.error("声音量合规定为：[50,100]")
    else:
        assert 0, logger.error("【拾音】声音大小不符合规定")

    print(res.json())


# 根据id执行用例
def get_yinping_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getAudioConfig"

    res = RequestUtil.all_send_request('GET', url, params=data_yaml)

    code = res.json()['code']

    judge_code(code=code)
    if id == 1:
        assert res.json()['data']['audioInStatus'] == 1 or res.json()['data']['audioInStatus'] == -1
        if res.json()['data']['audioInStatus'] == 1:
            logger.error('打开拾音功能失败')

        info = eg.ccbox('拾音关闭听不见', '选择', choices=('成功', '失败'))
        if info:
            assert 1
        else:
            assert 0, logger.info('拾音关闭失败')

    elif id == 2:
        res.json()['data']['audioInStatus'] == 2, logger.info('打开拾音功能失败')

        info = eg.ccbox('拾音打开能听见', '选择', choices=('成功', '失败'))
        if info:
            assert 1
        else:
            assert 0, logger.info('拾音打开能听见失败')

    elif id == 3:
        res.json()['data']['audioIn'] == 100, logger.info('开启拾音功能恢复成默认音量失败')
    elif id == 4:
        res.json()['data']['audioIn'] == 100, logger.info('拾音默认不修改失败')

    elif id == 5:
        res.json()['data']['audioOutStatus'] == 1, logger.info('关闭扩音功能失败')

        info = eg.ccbox('扩音关闭听不见', '选择', choices=('成功', '失败'))
        if info:
            assert 1
        else:
            assert 0, logger.info('扩音关闭失败')

    elif id == 6:
        res.json()['data']['audioOutStatus'] == 2, logger.info('打开扩音功能失败')

        info = eg.ccbox('扩音打开能听见', '选择', choices=('成功', '失败'))
        if info:
            assert 1
        else:
            assert 0, logger.info('扩音打开能听见失败')

    elif id == 7:
        res.json()['data']['audioOut'] == 100, logger.info('开启扩音功能恢复成默认音量失败')
    elif id == 8:
        res.json()['data']['audioOut'] == 100, logger.info('扩音默认不修改失败')

    print(res.json())


#  查询出所有音量数据并且返回data数据
def get_yinping_data():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getAudioConfig"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    return res.json()['data']

# ——————————————————音频结束------------------------------


# --------------------------- osd 相关——————————————————————————————————————————————————————————
# 默认
def get_osd():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getOSDConfig"
    data = change_channelCode()
    res = RequestUtil.all_send_request('GET', url, params=data)
    LIST_OSD_DATA.append(res.json()['data'])
    code = res.json()['code']
    judge_code(code=code)
    assert res.json()['data'] != None, logger.error("osd 获取不到数据,返回数据为空")
    print(res.json())


#
def get_osd_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getOSDConfig"
    data = change_channelCode()
    res = RequestUtil.all_send_request('GET', url, params=data)
    code = res.status_code
    judge_code(code=code)
    if id == 1:

      chioce_info = eg.ccbox("【星期】水印【显示】", '选择', choices=('显示', '未显示'))
      if chioce_info:
        assert 1
      else:
        assert 0, logger.error('【星期】水印【显示】不通过')

    elif id == 2:

      chioce_info = eg.ccbox("【星期】水印【不显示】", '选择', choices=('不显示', '显示'))
      if chioce_info:
        assert 1
      else:
        assert 0, logger.error('【星期】水印【不显示】不通过')

    elif id == 3:

      assert res.json()['data']['dateDisplay'] == 1, logger.error('日期水印不显示')

      chioce_info = eg.ccbox("【日期】水印【显示】", '选择', choices=('显示', '不显示'))
      if chioce_info:
          assert 1
      else:
          assert 0, logger.error('【日期】水印【显示】不通过')

    elif id == 4:
      assert res.json()['data']['dateDisplay'] == 0, logger.error('日期水印出现未知错误或者显示')

      chioce_info = eg.ccbox("【日期】水印【不显示】", '选择', choices=('不显示', '显示'))
      if chioce_info:
          assert 1
      else:
          assert 0, logger.error('【日期】水印【不显示】不通过')

    elif id == 5:
      assert res.json()['data']['channelDisplay'] == 1

      chioce_info = eg.ccbox("【通道】水印【显示】", '选择', choices=('显示', '不显示'))
      if chioce_info:
          assert 1
      else:
          assert 0, logger.error('【通道】水印【显示】不通过')

    elif id == 6:
      assert res.json()['data']['channelDisplay'] == 0

      chioce_info = eg.ccbox("【通道】水印【不显示】", '选择', choices=('不显示', '显示'))
      if chioce_info:
          assert 1
      else:
          assert 0, logger.error('【通道】水印【不显示】不通过')

    elif id == 7:
      assert res.json()['data']['dateDisplay'] == 0, logger.error("日期，传空数据，显示发生变化")

      chioce_info = eg.ccbox("【日期】水印【不显示】", '选择', choices=('不显示', '显示'))
      if chioce_info:
          assert 1
      else:
          assert 0, logger.error('【通道】水印【不显示】不通过')

    elif id == 8:
      assert res.json()['data']['dateDisplay'] == 1, logger.error("日期,传0,1其他数据，返回值应该为显示")

    elif id == 9:
      assert res.json()['data']['channelDisplay'] == 1, logger.error('通道传0，1以外的数应该为显示')

      chioce_info = eg.ccbox("【通道】水印【显示】", '选择', choices=('显示', '不显示'))
      if chioce_info:
          assert 1
      else:
          assert 0, logger.error('【通道】水印【显示】不通过')

    elif id == 10:
      assert res.json()['data']['channelDisplay'] == 0, logger.error('通道传空，返回数据应该为不显示')

      chioce_info = eg.ccbox("【通道】水印【不显示】", '选择', choices=('不显示', '显示'))
      if chioce_info:
          assert 1
      else:
          assert 0, logger.error('【通道】水印【不显示】不通过')

    print(res.json())


# osd 的compositions部分
def get_compositions_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getOSDConfig"
    data = change_channelCode()
    res = RequestUtil.all_send_request('GET', url, params=data)
    code = res.status_code
    judge_code(code=code)
    compositions = res.json()['data']['compositions']
    if id == 1:
        assert compositions[0]['display'] == 1 and compositions[0]['index'] == 1, logger.error("【compositions 显示】出错")

        chioce_info = eg.ccbox("叠加字符小字段成功【显示】打开", '选择', choices=('成功', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('叠加字符小字段成功【显示】出错')

    elif id == 2:
        assert compositions[0]['display'] == 0 and compositions[0]['index'] == 1, "隐藏失败"

        chioce_info = eg.ccbox("叠加字符小字段成功隐藏", '选择', choices=('成功', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('叠加字符小字段隐藏失败')

    elif id == 3:
        assert compositions[0]['display'] == 0 and compositions[0]['index'] == 1, "传空应该不显示"

        chioce_info = eg.ccbox("display传空应该不显示", '选择', choices=('成功', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('display传空应该不显示失败')

# --------------------------- osd 结束——————————————————————————————————————————————————————————


# --------------------------  移动侦测 -------------------------------------------------------------
#  移动侦测默认情况
def get_yidongzhence():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getMDStatus"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    code = res.json()['code']
    judge_code(code=code)
    # 保存出厂设置的默认值
    LIST_YIDONG_DATA.append(res.json()['data'])

    # 事件开关状态 1开 2关
    eventStatus = res.json()['data']['eventStatus']

    # 灵敏度 1-100
    sensitivity = res.json()['data']['sensitivity']

    # 布放时间开启状态 1 全天 2 部分
    defenceStatus = res.json()['data']['defenceStatus']

    # 智能开关状态
    smartStatus = res.json()['data']['smartStatus']

    # 是否抓图 1为开 2 关 -1不支持
    screenShotStatus = res.json()['data']['screenShotStatus']

    # 人形= 1 电动 = 2
    smartTypes = res.json()['data']['smartType']

    # 布放时间
    defenceTime = res.json()['data']['defenceTime']

    shebei = read_shebei_yaml()

    assert eventStatus == 1, logger.error('事件开关:【关】')

    assert defenceStatus == 1, logger.error("默认不为全天开启")

    assert smartStatus == 2 or smartStatus == -1, logger.error("智能开关:【开】")

    if shebei['xinghao'] == "V50" or shebei['xinghao'] == "v50":
        if sensitivity == 70:
            assert 1, logger.error('v50默认不为70')
    else:
        if sensitivity <= 100 and sensitivity >= 1:
            assert 1, logger.error('移动侦测的灵敏度为'+sensitivity)

    # 布放时间待完善
    if defenceStatus == 1:
        assert defenceTime == None ,logger.error(res.json()['data']['defenceTime'])
    elif defenceStatus == 2:
        assert 0, logger.error('默认为部分时间段打开')


#  根据id来判断结果(非布放时间段)
def get_yidongzhence_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getMDStatus"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    code = res.json()['code']
    judge_code(code=code)

    # 事件开关状态 1开 2关
    eventStatus = res.json()['data']['eventStatus']

    # 灵敏度 1-100
    sensitivity = res.json()['data']['sensitivity']

    # 布放时间开启状态 1 全天 2 部分
    defenceStatus = res.json()['data']['defenceStatus']

    # 智能开关状态
    smartStatus = res.json()['data']['smartStatus']

    if id == 1:
        assert eventStatus == 2, '事件开关关闭【失败】'
        chioce_info = eg.ccbox("关闭事件开关触发云存不成功", '选择', choices=('正确', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('移动侦测开关关闭后上传云存成功')

    elif id == 2:
        assert eventStatus == 1, '事件开关开启【失败】'
        chioce_info = eg.ccbox("开启事件开关触发云存成功", '选择', choices=('正确', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('移动侦测开关开启后上传云存失败')

    elif id == 3:
        assert eventStatus == 1, logger.error('事件开关设置0为保持与上一次不变【失败】')

    elif id == 4:
        assert sensitivity == LIST_YIDONG_DATA[0]['sensitivity'], logger.error('灵敏度设置【失败】')

    elif id == 5 and LIST_YIDONG_DATA[0]['smartStatus'] != -1:
        assert smartStatus == 1, logger.error('智能开关状态打开【失败】')
        chioce_info = eg.ccbox("智能状态开启是否有云存(人和物体分别去触发)", '选择', choices=('正确', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('移动侦测【智能开关】开关【开启】后上传云存失败')

    elif id == 6 and LIST_YIDONG_DATA[0]['smartStatus'] != -1:
        assert smartStatus == 1, logger.error('智能开关状态为0时【失败】')

    elif id == 7:
        assert defenceStatus == LIST_YIDONG_DATA[0]['defenceStatus'], logger.error('布放状态值为0时失败')
        # LIST_YIDONG_BUCHUAN.append(res.json()['data']['defenceStatus'])
    elif id == 8:
        assert defenceStatus == 1
        # assert LIST_YIDONG_BUCHUAN[0]['defenceStatus'] == 1
    elif id == 9:
        assert sensitivity == 100, logger.error('灵敏度设置100失败')
    elif id == 10:
        assert sensitivity == 1, logger.error('灵敏度设置为1失败')
    elif id == 11:
        assert defenceStatus == 1, logger.error('布放时间为全天')
        chioce_info = eg.ccbox("开启【全天】事件触发云存成功", '选择', choices=('正确', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('移动侦测设置为【全天】后上传云存失败')

    elif id == 12:
        assert eventStatus == 1, logger.error('事件开关开启失败')
        chioce_info = eg.ccbox("开启事件开关触发云存成功", '选择', choices=('正确', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('移动侦测开关开启后上传云存失败')

    elif id == 13:
        assert eventStatus == 2, logger.error('事件开关关闭失败')
        chioce_info = eg.ccbox("关闭事件开关触发云存失败", '选择', choices=('正确', '失败'))
        if chioce_info:
            assert 1
        else:
            assert 0, logger.error('移动侦测开关开关闭后上传云存成功')

# 布放事件段
def get_timeDuration_id(id):
    pass


# ----------------------------移动侦测结束-----------------------------------------------------------


# ----------------------------区域入侵--------------------------------------------------------------
def get_quyuruqin():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getAreaAlarmStatus"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    # code码
    code = res.json()['code']

    judge_code(code=code)

    # 事件开关
    eventStatus = res.json()['data']['eventStatus']

    # 智能开关状态
    smartStatus = res.json()['data']['smartStatus']

    # 布防时间开启状态（1：默认全部打开，2：部分时间段打开）
    defenceStatus = res.json()['data']['defenceStatus']

    # 布防时间（按周
    defenceTime = res.json()['data']['defenceTime']

    # 预留，动作值1=进入，2=离开，当前仅要求进
    actions = res.json()['data']['action']

    # 是否抓图（1：开，2：关，-1：不支持）
    screenShotStatus = res.json()['data']['screenShotStatus']

    # 当前灵敏度（范围1-100，存在阈值设置的设备出厂和提测时默认应将灵敏度调得更为灵敏）
    sensitivity = res.json()['data']['sensitivity']

    # 1=人形、2=电动车（预留），不支持忽略
    smartTypes = res.json()['data']['smartType']

    # 设备画面是否显示区域，1=显示，2=不显示,0默认不修改
    showArea = res.json()['data']['showArea']

    data = read_shebei_yaml()
    LIST_QUYURUQIN_DATA.append(res.json()['data'])

    assert res.json()['data'] != None, logger.error('区域入侵数据返回为空')
    assert eventStatus == 1 or eventStatus == -1, logger.error('默认区域入侵事件开关:【关】')
    assert defenceStatus == 1, logger.error("默认不为全天开启")
    assert smartStatus == 1 or smartStatus == -1, logger.error("默认智能开关:【关】")
    if data['xinghao'] == 'V50' or 'v50':
        assert sensitivity == 70, logger.error("当前灵明度为" + sensitivity)
    else:
        assert sensitivity <= 100 and sensitivity >= 1
    assert showArea == 2 or showArea == -1, logger.error("默认显示布放区域")

    # 进范围报警还是出范围报警
    for action in actions:
        if action == 1:
            logger.info("默认为进范围报警")
            assert 1
        elif action == 2:
            logger.info("默认为出范围报警")
            assert 1

        # 布放时间待完善
    if defenceStatus == 1:
        assert 1
    elif defenceStatus == 2:
        assert defenceTime != None, logger.error("返回为空")

    print(res.json(), "默认全屏未完成")


def get_quyuruqin_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getAreaAlarmStatus"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)

    # 事件开关
    eventStatus = res.json()['data']['eventStatus']

    # 智能开关状态
    smartStatus = res.json()['data']['smartStatus']

    # 布防时间开启状态（1：默认全部打开，2：部分时间段打开）
    defenceStatus = res.json()['data']['defenceStatus']

    # 当前灵敏度（范围1-100，存在阈值设置的设备出厂和提测时默认应将灵敏度调得更为灵敏）
    sensitivity = res.json()['data']['sensitivity']

    # code码
    code = res.status_code

    judge_code(code=code)
    if id == 1:
        assert eventStatus == 1, 'eventStatus字段传0，失败了'
    elif id == 2:
        assert eventStatus == 1, 'eventStatus字段传null或者不传，失败了'
    elif id == 3:
        assert eventStatus == 1, 'eventStatus字段传1，失败了'
    elif id == 4:
        assert eventStatus == 2, 'eventStatus字段传2，失败了'
    elif id == 5:
        assert eventStatus == 2, 'eventStatus字段传0、1、2以外的数字，失败了'
    elif id == 6:
        assert sensitivity == LIST_QUYURUQIN_DATA[0]['sensitivity'], 'sensitivity字段传0，失败了'
    elif id == 7:
        assert sensitivity == LIST_QUYURUQIN_DATA[0]['sensitivity'], 'sensitivity字段不传，失败了'
    elif id == 8:
        assert sensitivity == 20, 'sensitivity=20，失败了'
    elif id == 9:
        assert sensitivity == 40, 'sensitivity=40，失败了'
    elif id == 10:
        assert sensitivity == 60, 'sensitivity=60，失败了'
    elif id == 11:
        assert sensitivity == 75, 'sensitivity=75，失败了'
    elif id == 12:
        assert sensitivity == 100, 'sensitivity=100，失败了'
    elif id == 13:

        # # 读取到的配置信息
        # data = read_data_yaml()
        # # json数据
        # json = {
        #     "eventStatus": 2,
        #     "deviceCode": data['deviceCode'],
        # }
        # # token鉴权
        # headers = {"token": data['token']}
        # RequestUtil.all_send_request('post', url, json=json, headers=headers)

        assert smartStatus == 1, 'smartStatus=1，失败了'

        info = eg.ccbox('智能状态开关打开，是否有云存', '选择', choices=('有云存', '没有云存'))
        if info:
            assert 1
        else:
            assert 0, logger.error('区域入侵智能状态开启没有云存')

    elif id == 14:
        assert smartStatus == 2, 'smartStatus=2，失败了'

        info = eg.ccbox('智能状态开关关闭，没有云存', '选择', choices=('没有云存', '有云存'))
        if info:
            assert 1
        else:
            assert 0, logger.error('区域入侵智能状态关闭有云存')

    elif id == 15:
        assert smartStatus == 2, 'smartStatus=0，失败了'
    elif id == 16:
        assert defenceStatus == 1, 'defenceStatus=1，失败了'
    elif id == 17:
        assert smartStatus == 2, 'smartStatus=3，失败了'
    elif id == 18:
        assert smartStatus == 2, 'smartStatus=null，失败了'
    elif id == 19:
        assert defenceStatus == 1, 'defenceStatus =0，失败了'
    elif id == 20:
        assert defenceStatus == 1, 'defenceStatus =null，失败了'
    elif id == 21:
        assert defenceStatus == 2, 'defenceStatus =2，失败了'
# ----------------------------区域入侵结束-----------------------------------------------------------


# --------------------------- 告      警 ----------------------------------------------------------
def get_gaojing_yidong():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getEventAlarmOut"
    data_yaml['eventType'] = 1  # 1移动  # 2 区域
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    code = res.json()['code']
    judge_code(code=code)

    # 国标告警消息输出开关状态（1：开，2：关），默认开
    assert res.json()['data']['gbAlarmStatus'] != None, logger.error('没有国标！！！')

    assert res.json()['data']['gbAlarmStatus'] == 1, logger.error("国标默认为关")

    if res.json()['data']['audioAlarmStatus'] == -1 and res.json()['data']['lightAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持声音和灯光告警功能')
    elif res.json()['data']['audioAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持声音告警功能')
    elif res.json()['data']['lightAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持灯光告警功能')

    # 将出场后的默认值保存到列表
    LIST_GAOJING_DATA.append(res.json()['data'])

    # 灯光告警类型，1=常亮，2=闪烁
    lightAlarmType = res.json()['data']['lightAlarmType']

    # 告警声音文件，声音告警开关为关的时候也需要返回数据
    audioAlarmFiles = res.json()['data']['audioAlarmFiles']

    # 声音告警开关状态（1：开，2：关）0=默认不修改
    audioAlarmStatus = res.json()['data']['audioAlarmStatus']

    # 告警灯光开关状态（1：开，2：关），0=默认不修改
    lightAlarmStatus = res.json()['data']['lightAlarmStatus']

    # 声音播放次数（范围1-6次），0=默认不修改
    audioPlayCount = res.json()['data']['audioPlayCount']

    # 闪烁频率，1=高，2=中，3=低 ，0=默认不修改
    lightAlarmFrequency = res.json()['data']['lightAlarmFrequency']

    # 停留时间（单位s）（范围5-30s），0默认不修改
    lightAlarmTime = res.json()['data']['lightAlarmTime']

    # 国标告警消息输出开关状态（1：开，2：关），默认开
    gbAlarmStatus = res.json()['data']['gbAlarmStatus']

    if lightAlarmType == 1:
        logger.info('该设备默认为常亮')
    elif lightAlarmType == 2:
        logger.info('该设备默认为闪烁')

    assert lightAlarmStatus == 2 or lightAlarmStatus == -1, logger.error("告警灯光默认为: 开")
    assert audioAlarmStatus == 2 or audioAlarmStatus == -1, logger.error("声音告警为：开")
    assert audioPlayCount >= 1 and audioPlayCount <= 6, logger.error("声音播放次数不在 [1,6]")

    # 初始长度
    if len(audioAlarmFiles) == 4:
        assert 1
    elif len(audioAlarmFiles) > 4:
        assert 0, logger.error('告警音长度大于4')
    elif len(audioAlarmFiles) < 4:
        assert 0, logger.error('告警长度小于4')
    elif audioAlarmFiles == None:
        assert 0, logger.error('返回数据为空')
    assert lightAlarmTime >= 5 and lightAlarmTime <= 30, "停留时间不在[5,30]"

    print(res.json())


def get_gaojing_quyu():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getEventAlarmOut"
    data_yaml['eventType'] = 2  # 1移动  # 2 区域
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)

    code = res.json()['code']
    judge_code(code=code)

    # 国标告警消息输出开关状态（1：开，2：关），默认开
    assert res.json()['data']['gbAlarmStatus'] != None, logger.error('没有国标！！！')

    assert res.json()['data']['gbAlarmStatus'] == 1, logger.error("国标默认为关")

    if res.json()['data']['audioAlarmStatus'] == -1 and res.json()['data']['lightAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持声音和灯光告警功能')
    elif res.json()['data']['audioAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持声音告警功能')
    elif res.json()['data']['lightAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持灯光告警功能')

    # 将出场后的默认值保存到列表
    LIST_GAOJING_DATA.append(res.json()['data'])

    # 灯光告警类型，1=常亮，2=闪烁
    lightAlarmType = res.json()['data']['lightAlarmType']

    # 告警声音文件，声音告警开关为关的时候也需要返回数据
    audioAlarmFiles = res.json()['data']['audioAlarmFiles']

    # 声音告警开关状态（1：开，2：关）0=默认不修改
    audioAlarmStatus = res.json()['data']['audioAlarmStatus']

    # 告警灯光开关状态（1：开，2：关），0=默认不修改
    lightAlarmStatus = res.json()['data']['lightAlarmStatus']

    # 声音播放次数（范围1-6次），0=默认不修改
    audioPlayCount = res.json()['data']['audioPlayCount']

    # 闪烁频率，1=高，2=中，3=低 ，0=默认不修改
    lightAlarmFrequency = res.json()['data']['lightAlarmFrequency']

    # 停留时间（单位s）（范围5-30s），0默认不修改
    lightAlarmTime = res.json()['data']['lightAlarmTime']

    # 国标告警消息输出开关状态（1：开，2：关），默认开
    gbAlarmStatus = res.json()['data']['gbAlarmStatus']

    if lightAlarmType == 1:
        logger.info('该设备默认为常亮')
    elif lightAlarmType == 2:
        logger.info('该设备默认为闪烁')

    assert lightAlarmStatus == 2 or lightAlarmStatus == -1, logger.error("告警灯光默认为: 开")
    assert audioAlarmStatus == 2 or audioAlarmStatus == -1, logger.error("声音告警为：开")
    assert audioPlayCount >= 1 and audioPlayCount <= 6, logger.error("声音播放次数不在 [1,6]")

    # 初始长度
    if len(audioAlarmFiles) == 4:
        assert 1
    elif len(audioAlarmFiles) > 4:
        assert 0, logger.error('告警音长度大于4')
    elif len(audioAlarmFiles) < 4:
        assert 0, logger.error('告警长度小于4')
    elif audioAlarmFiles == None:
        assert 0, logger.error('返回数据为空')
    assert lightAlarmTime >= 5 and lightAlarmTime <= 30, "停留时间不在[5,30]"
    print(res.json())


def get_gaojing_yidong_id(id):

    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getEventAlarmOut"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)

    code = res.json()['code']
    judge_code(code=code)

    # 国标告警消息输出开关状态（1：开，2：关），默认开
    assert res.json()['data']['gbAlarmStatus'] != None, logger.error('没有国标！！！')

    assert res.json()['data']['gbAlarmStatus'] == 1, logger.error("国标默认为关")

    if res.json()['data']['audioAlarmStatus'] == -1 and res.json()['data']['lightAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持声音和灯光告警功能')
    elif res.json()['data']['audioAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持声音告警功能')
    elif res.json()['data']['lightAlarmStatus'] == -1:
        assert 0, logger.error('设备不支持灯光告警功能')

    # 灯光告警类型，1=常亮，2=闪烁
    lightAlarmType = res.json()['data']['lightAlarmType']

    # 声音告警开关状态（1：开，2：关）0=默认不修改
    audioAlarmStatus = res.json()['data']['audioAlarmStatus']

    # 告警灯光开关状态（1：开，2：关），0=默认不修改
    lightAlarmStatus = res.json()['data']['lightAlarmStatus']

    # 声音播放次数（范围1-6次），0=默认不修改
    audioPlayCount = res.json()['data']['audioPlayCount']

    # 闪烁频率，1=高，2=中，3=低 ，0=默认不修改
    lightAlarmFrequency = res.json()['data']['lightAlarmFrequency']

    # 停留时间（单位s）（范围5-30s），0默认不修改
    lightAlarmTime = res.json()['data']['lightAlarmTime']

    # 国标告警消息输出开关状态（1：开，2：关），默认开
    gbAlarmStatus = res.json()['data']['gbAlarmStatus']

    if id == 4:
       assert gbAlarmStatus == 1 or gbAlarmStatus == -1, logger.error('告警默认为开或者默认不支持')
    elif id == 5:
       assert gbAlarmStatus == 2, logger.error('告警默认为关')
    elif id == 6:
       assert gbAlarmStatus == 2, logger.error('告警音默认不修改')
    elif id == 7:
       assert gbAlarmStatus == 2, logger.error('告警音默认不传')
    elif id == 8:
       assert audioAlarmStatus == 1 or audioAlarmStatus == -1, logger.error("告警音功能开启")
       info = eg.ccbox('告警音功能打开 在触发移动侦测需要播报告警音', '选择', choices=('有告警音', '无告警音'))
       if info:
           assert 1
       else:
           assert 0, logger.error('告警音功能开启，移动侦测没有触发告警音')

    elif id == 9:
       assert audioAlarmStatus == 2, logger.error("告警音功能关闭")
       info = eg.ccbox('告警音功能关闭 在触发移动侦测不播报告警音', '选择', choices=('有告警音', '无告警音'))
       if info:
           assert 1
       else:
           assert 0, logger.error('告警音功能关闭，移动侦测触发告警音')

    elif id == 10:
       assert audioAlarmStatus == 2, logger.error('告警音默认不修改')
    elif id == 11:
       assert audioAlarmStatus == 2, logger.error('告警音传空')

    elif id == 12:
       assert lightAlarmStatus == 1 or lightAlarmStatus == -1, ''
       info = eg.ccbox('告警灯光功能打开 在触发移动侦测需要点亮全彩补光灯', '选择', choices=('有灯光', '无灯光'))
       if info:
           assert 1
       else:
           assert 0, logger.error('告警灯光功能打开，触发移动侦测没有点亮全彩补光灯')

    elif id == 13:
       assert lightAlarmStatus == 2
       info = eg.ccbox('告警灯光功能关闭 在触发移动侦测不能点亮全彩补光灯', '选择', choices=('无灯光', '有灯光'))
       if info:
           assert 1
       else:
           assert 0, logger.error('告警灯光功能关闭，触发移动侦测点亮全彩补光灯')

    elif id == 14:
        assert lightAlarmStatus == 2
    elif id == 15:
        assert lightAlarmStatus == 2
    elif id == 16:
        assert lightAlarmTime == 5
        info = eg.ccbox('告警灯光停留时间是否为5秒', '选择', choices=('是', '否'))
        if info:
            assert 1
        else:
            assert 0, logger.error('告警灯光停留时间配置失败')

    elif id == 17:
        assert lightAlarmTime == 5
    elif id == 18:
        assert lightAlarmTime == 5
    elif id == 19:
        assert audioPlayCount == 6
        info = eg.ccbox('告警声音是否响6次', '选择', choices=('是', '否'))
        if info:
            assert 1
        else:
            assert 0, logger.error('告警灯光停留时间配置失败')

    elif id == 20:
        assert audioPlayCount == 6
    elif id == 21:
        assert audioPlayCount == 6

    elif id == 22:
        assert lightAlarmType == 1
        info = eg.ccbox('是否为常亮模式', '选择', choices=('是', '否'))
        if info:
            assert 1
        else:
            assert 0, logger.error('常亮配置失败')

    elif id == 23:
        assert lightAlarmType == 2
        info = eg.ccbox('是否为闪烁模式', '选择', choices=('是', '否'))
        if info:
            assert 1
        else:
            assert 0, logger.error('闪烁配置失败')

    elif id == 24:
        assert lightAlarmType == 2
    elif id == 25:
        assert lightAlarmType == 2

    elif id == 26:
        assert lightAlarmFrequency == 1 or lightAlarmFrequency == -1
        info = eg.ccbox('闪烁频率高', '选择', choices=('是', '否'))
        if info:
            assert 1
        else:
            assert 0, logger.error('闪烁配置不符合要求【高】')

    elif id == 27:
        assert lightAlarmFrequency == 2
        info = eg.ccbox('闪烁频率高', '选择', choices=('是', '否'))
        if info:
            assert 1
        else:
            assert 0, logger.error('闪烁配置不符合要求【中】')

    elif id == 28:
        assert lightAlarmFrequency == 3
        info = eg.ccbox('闪烁频率高', '选择', choices=('是', '否'))
        if info:
            assert 1
        else:
            assert 0, logger.error('闪烁配置不符合要求【低】')

    elif id == 29:
        assert lightAlarmFrequency == 3
    elif id == 30:
        assert lightAlarmFrequency == 3
    print(res.json())
# -------------------------------  告警结束 -----------------------------------


# -------------------------------- 夜视 --------------------------------------

# 夜视默认
def get_yeshi():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getNightVisionConfig"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    # code码
    code = res.status_code
    # 判断code码
    judge_code(code=code)

    str = '设备默认支持：'

    supportedLightTypes = res.json()['data']['supportedLightTypes']
    currentLightType = res.json()['data']['currentLightType']
    lightnessType = res.json()['data']['lightnessType']

    # 将默认获取到的数据存储在队列中
    LIST_YESHI_DATA.append(res.json()['data'])

    # 本设备支持（后期可添加设备的类型）
    for supportedLightType in supportedLightTypes:
        if supportedLightType == 1:
            str+='【红外】'

        elif supportedLightType == 2:
            str+='【全彩】'

        elif supportedLightType == 3:
            str+='【智能全彩】'

        elif supportedLightType == 4:
            str+='【星光】'

    # 输出设备的类型
    logger.info(str)

    # 当前设备为啥模式
    if currentLightType == 1:
        assert 1
    elif currentLightType == 2:
        assert 0, logger.info('默认为全彩')
    elif currentLightType == 3:
        assert 0, logger.info('默认为智能全彩')
    elif currentLightType == 4:
        assert 0, logger.info('默认为星光')

    # 亮度范围
    assert lightnessType >= 0 and lightnessType <= 100, '亮度出现过错误'
    print(res.json())

# 设置夜视
def get_yeshi_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getNightVisionConfig"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    code = res.status_code
    judge_code(code=code)

    str = ''

    # 根据设备判断执行那些数据
    supportedLightTypes = LIST_YESHI_DATA[0]['supportedLightTypes']

    currentLightType = res.json()['data']['currentLightType']
    lightnessType = res.json()['data']['lightnessType']

    if id == 1 and 1 in supportedLightTypes:
       assert currentLightType == 1
    elif id == 2 and 2 in supportedLightTypes:
       assert currentLightType == 2
    elif id == 3 and 3 in supportedLightTypes:
       assert currentLightType == 3
    elif id == 4:
       assert lightnessType == 0 and currentLightType == 2, logger.error('设置亮度为0失败')
       info = eg.ccbox('现在灯光看不到了', '选择', choices=('正确', '失败'))
       if info:
           assert 1
       else:
           assert 0, '灯光亮度为0失败'

    elif id == 5:
       assert lightnessType == 20 and currentLightType == 2, logger.error('亮度为20配置失败')
       info = eg.ccbox('现在灯光亮度设置为:20', '选择', choices=('正确', '失败'))
       if info:
           assert 1
       else:
           assert 0, logger.error('设置亮度为20失败')

    elif id == 6:
       assert lightnessType == 40 and currentLightType == 2, logger.error('亮度为40配置失败')
       info = eg.ccbox('现在灯光亮度设置为:40', '选择', choices=('正确', '失败'))
       if info:
           assert 1
       else:
           assert 0, logger.error('设置亮度为40失败')

    elif id == 7:
       assert lightnessType == 60 and currentLightType == 2, logger.error('亮度为60配置失败')
       info = eg.ccbox('现在灯光亮度设置为:60', '选择', choices=('正确', '失败'))
       if info:
           assert 1
       else:
           assert 0, logger.error('设置亮度为60失败')

    elif id == 8:
       assert lightnessType == 80 and currentLightType == 2, logger.error('亮度为80配置失败')
       info = eg.ccbox('现在灯光亮度设置为:80', '选择', choices=('正确', '失败'))
       if info:
           assert 1
       else:
           assert 0, logger.error('设置亮度为80失败')

    elif id == 9:
       assert lightnessType == 100 and currentLightType == 2
       info = eg.ccbox('现在灯光亮度设置为:100', '选择', choices=('正确', '失败'))
       if info:
           assert 1
       else:
           assert 0, logger.error('设置亮度为100失败')

    elif id == 10:
       assert lightnessType == 10 and currentLightType == 2
       info = eg.ccbox('查看设备补光灯亮度是否低于值为20时的亮度， 补光灯亮度正常', '选择', choices=('正确', '失败'))
       if info:
           assert 1
       else:
           assert 0, '补光灯亮度不正常 失败了'

# -------------------------------- 夜视 结束--------------------------------------


# ------------------------------- ONVIF --------------------------------------
def get_ONVIF():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getDeviceOnvif"
    data = change_channelCode()
    res = RequestUtil.all_send_request('GET', url, params=data)

    version = res.json()['data']['version']
    status = res.json()['data']['status']
    code = res.json()['code']
    judge_code(code=code)
    if status == 1:
        assert 1
    elif status == 2:
        assert 0, logger.error('ONVIF 默认关闭')
    logger.error('当前ONVIF版本为=' + version)
    print(res.json())


def get_onvif_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getDeviceOnvif"
    data = change_channelCode()
    res = RequestUtil.all_send_request('GET', url, params=data)
    status = res.json()['data']['status']
    code = res.json()['code']
    judge_code(code=code)
    if id == 1:
        assert status == 1
        info = eg.ccbox('onvif已经打开', '选择', choices=('正确', '失败'))
        if info:
            assert 1
        else:
            assert 0, 'onvif打开失败'

    elif id == 2:
        assert status == 2
        info = eg.ccbox('onvif已经关闭', '选择', choices=('正确', '失败'))
        if info:
            assert 1
        else:
            assert 0, 'onvif关闭失败'

    elif id == 3:
        assert status == 2
    elif id == 4:
        assert status == 2
    elif id == 5:
        assert status == 2
    elif id == 6:
        assert status == 2
    elif id == 7:
        assert status == 2


# ------------------------------- ONVIF 结束--------------------------------------

# -------------------------------- 视频流 -------------------------------
def get_shiping_liu():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getVideoConfig"

    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    data = read_shebei_yaml()
    code = res.json()['code']
    judge_code(code=code)
    # 码率参考范围（e.g：3024~4096，单位kb）
    rateLimit = res.json()['data']['rateLimit']

    # 帧率范围
    frameRateLimit = res.json()['data']['frameRateLimit']

    # 当前图像质量（来自于接口返回数据），为""表示不更改
    currImageQuality = res.json()['data']['currImageQuality']

    # I帧间隔（单位：ms）为0表示不更改
    iframeInterval = res.json()['data']['iframeInterval']

    # 当前帧率，为0表示不更改（来自于接口返回数据）
    currFrameRate = res.json()['data']['currFrameRate']

    # Points参照的分辨率（数据格式eg：1920*1080），以1920*1080P分辨率为例，采用左下坐标（0,0）,左上（0,1080）,右上（1920,1080）,右下（1920,0）为参考坐标，其它分辨率类推。
    resolution = res.json()['data']['resolution']

    # 当前码率类型（1：固定码率，2：变码率）,默认使用变码率
    rateType = res.json()['data']['rateType']

    # 当前分辨率（来自于接口返回数据），为""表示不更改，分辨率格式统一W*H
    currResolution = res.json()['data']['currResolution']

    # 码率或码率上限（单位：kb）
    rate = res.json()['data']['rate']

    # 视频编码方式（设备返回格式严格要求为H.264、H.265）
    encodeType = res.json()['data']['encodeType']

    # 图像质量（应以能被人明显识别的文字描述，如中文描述e.g：高、中、低等，英文：H、M、L）
    imageQuality = res.json()['data']['imageQuality']

    # 当前编码方式（EncodeType中的值）
    currEncode = res.json()['data']['currEncode']

    # frameRateLimit = tuple(frameRateLimit)
    if data['xinghao'] == 'V50' or data['xinghao'] == 'v50':
        assert currEncode == 'H.265', logger.error("默认编码方式不为H.265")
        assert rateType == 2,  logger.error("默认不为变码率")
        assert iframeInterval % 2000 == 0, logger.error('帧率应该为2000ms的倍数')
        assert currFrameRate >= 15 and currFrameRate in frameRateLimit, logger.error("【返回必需在范围内且大于15】"+"当前设备值为："+str(currFrameRate)+"范围为："+str(frameRateLimit))
    else:
        assert currEncode == 'H.265' or currEncode == 'H.264'
        assert rateType == 2, logger.error("默认不为变码率")
        assert iframeInterval % 2000 == 0, logger.error('帧率应该为2000ms的倍数')

    print(res.json())


# ---------------------------- 本地录像 -------------------------------------------
def get_bendiluxiang():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getLocalStorageConfig"
    data = change_channelCode()
    res = RequestUtil.all_send_request('GET', url, params=data)
    code = res.json()["code"]
    judge_code(code=code)

    streamType = res.json()["data"]["streamType"]
    defenceTime = res.json()["data"]["defenceTime"]
    # 存储类型（0、不录像，1、全天录像，2、定时录像，3、移动侦测录像）
    storageType = res.json()["data"]["storageType"]

    if res.json()['data'] != None:
        assert 1
        # 主子码流
    if streamType == 0:
        logger.error('本地录像为主码流')


    elif streamType == 1:
        logger.error('本地录像为子码流')
    else:
        logger.error('未知参数')

    # 录像方式
    if storageType == 0:
        logger.error("本地录像为不录像")
    elif storageType == 1:
        logger.error("本地录像为全天录像")
    elif storageType == 2:
        logger.error("本地录像为定时录像")
    elif storageType == 3:
        logger.error("本地录像为移动侦测录像")
    else:
        logger.error("未知错误")
    print(res.json())


# ------------------------ 国标 --------------------------------------------------
def get_guobiao():
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getGBConfig"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)

    # SIP端口
    sipPort = res.json()['data']['sipPort']

    # Sip服务id
    sipServerID = res.json()['data']['sipServerID']

    # SIP地址
    sipHost = res.json()['data']['sipHost']

    # 心跳超时次数
    heartBeatNum = res.json()['data']['heartBeatNum']

    # 注册有效期，单位：s，默认：86400秒（24小时），兼容以前老设备
    expirationTime = res.json()['data']['expirationTime']

    # 心跳间隔，单位：s
    hearBeatTime = res.json()['data']['hearBeatTime']

    code = res.json()['code']
    judge_code(code=code)
    assert hearBeatTime == 30, logger.error('心跳范围过大:'+hearBeatTime)

    print(res.json()['data'])


# ----------------------- 本地储存 -------------------------------------------------
def get_bendicunchu():
    data_yaml = read_data_yaml()

    url = "https://mojing.sctel.com.cn/monitor/terminal/terminal/sdCardInfo/" + data_yaml['deviceCode']
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    data = res.json()['data']
    code = res.json()['code']
    judge_code(code=code)
    if data != None:
        assert 1
    if data['sdStat'] == 0:
        logger.error('无卡')
    elif data['sdStat'] == 1:
        logger.error('有卡')
    elif data['sdStat'] == 3:
        logger.error('有卡已初始化')

    assert data['sdCardSize'] * 1024 >= data['sdCardAvailableSize'] + data['sdCardUsedSize'], logger.error('sdk卡的内存小于可用和剩余的内存之和')


# ---------------------- 网络 ------------------------------------------------------
def get_wangluo():
    new_mac = ''
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getNetInfo"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    code = res.json()['code']
    judge_code(code)
    LIST_WANGLUO_DATA.append(res.json()['data'])
    netCards = res.json()['data']['netCards']
    # mac码
    mac = netCards[0]['mac']

    # 是否为动态（0： 静态 ， 1： 动态）
    isDynamic = netCards[0]['isDynamic']

    # 是否连接启用（0 否， 1：是）
    status = netCards[0]['status']

    # 网卡类型（1 无线 ， 2： 有线）
    netCardType = netCards[0]['netCardType']

    # ip
    ip = netCards[0]['iP']

    assert isDynamic == 1, logger.error('默认不为动态')

    # 按 ” ：“ 分割接口获取到的mac
    macs = mac.split(':')
    # 将分割的参数组成一个新的字符串
    for mac in macs:
        new_mac += mac

    # 从配置文件中读取到参数
    deviceCode = read_data_yaml()['deviceCode']
    # deviceCode[5:18]为左闭右开
    if new_mac == deviceCode[5:18]:
        assert 1, logger.error("mac值错误：" + mac)

    if status == 1 and netCardType == 1:
       logger.info('无线已启用')
    elif status == 1 and netCardType == 2:
       logger.info('有线已启用')
    elif status == 0 and netCardType == 1:
       logger.error('无线未启用')
    elif status == 0 and netCardType ==2:
       logger.error('无线未启用')

    logger.info("设备ip为：" + ip)


def get_wangluo_id(id):
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getNetInfo"
    res = RequestUtil.all_send_request('GET', url, params=data_yaml)
    code = res.json()['code']
    judge_code(code)
    netCards = res.json()['data']['netCards']
    if id == 1:
        assert netCards[0]['isDynamic'] == 1
        logger.info('动态转静态成功')
    elif id == 2:
        assert netCards[0]['isDynamic'] == 2, logger.error('动态转静态失败')
    elif id == 3:
        assert netCards[0]['isDynamic'] == 1, logger.error('静态转动态失败')
        logger.info('互相转换没有问题')


# -------------------图像 ---------------------------------
def get_tuxiang():
    i = 1
    url = "https://mojing.sctel.com.cn/monitor/terminal/southInfo/getImageConfig"
    data = change_channelCode()
    res = RequestUtil.all_send_request('GET', url, params=data)
    code = res.json()['code']
    judge_code(code=code)
    assert res.json()['data']['model'] == 1, logger.error('model应该为默认值1')
    types = res.json()['data']['types']
    for type in types:
        params = type['params']
        for param in params:
            assert param['current'] <= 100 and param['current'] >= 0, logger.info(param['name'] + '不在[0,100]以内')
        i += 1
    print(res.json())